﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using ConsoleApp10;

namespace UnitTestProject10
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod] //添加是否不重复
        public void TestMethodAdd2()
        {
            OrderDetails newOrder = new OrderDetails();
            Goods goods1 = new Goods("a", 10);
            newOrder.Add(goods1, 3);
            Goods goods2 = new Goods("b", 9);
            newOrder.Add(goods2, 5);
            Goods goods3 = new Goods("c", 8);
            newOrder.Add(goods3, 13);
            OrderService testorderService1 = new OrderService();
            OrderService testorderService2 = new OrderService();
            testorderService1.AddOrder(newOrder);
            testorderService2.AddOrder(newOrder);
            testorderService2.AddOrder(newOrder);
        }
        [TestMethod] //删除是否成功
        public void TestMethodDel1()
        {
            OrderDetails newOrder = new OrderDetails();
            Goods goods1 = new Goods("a", 10);
            newOrder.Add(goods1, 3);
            Goods goods2 = new Goods("b", 9);
            newOrder.Add(goods2, 5);
            Goods goods3 = new Goods("c", 8);
            newOrder.Add(goods3, 13);
            OrderService testorderService = new OrderService();
            testorderService.AddOrder(newOrder);
            testorderService.DelOrder(1);
            testorderService.DelOrder(1);
        }
        [TestMethod] //修改是否成功
        public void TestMethodEdit1()
        {
            OrderDetails newOrder1 = new OrderDetails();
            OrderDetails newOrder2 = new OrderDetails();
            Goods goods1 = new Goods("a", 10);
            newOrder1.Add(goods1, 3);
            newOrder2.Add(goods1, 3);
            Goods goods2 = new Goods("b", 9);
            newOrder1.Add(goods2, 5);
            newOrder2.Add(goods2, 55);
            Goods goods3 = new Goods("c", 8);
            newOrder1.Add(goods3, 13);
            newOrder2.Add(goods3, 13);
            OrderService testorderService1 = new OrderService();
            OrderService testorderService2 = new OrderService();
            testorderService1.AddOrder(newOrder1);
            testorderService2.AddOrder(newOrder2);
            testorderService1.EditOrder(1, "b", 55);
            testorderService1.EditOrder(1, "d", 3);
            testorderService1.EditOrder(0, "b", 55);
        }
        [TestMethod] //排序是否成功
        public void TestMethodFind()
        {
            OrderDetails newOrder = new OrderDetails();
            Goods goods1 = new Goods("a", 10);
            newOrder.Add(goods1, 3);
            Goods goods2 = new Goods("b", 9);
            newOrder.Add(goods2, 5);
            Goods goods3 = new Goods("c", 8);
            newOrder.Add(goods3, 13);
            Customer me = new Customer("Tom");
            OrderService testorderService = new OrderService();
            testorderService.Buyer = "Tom";
            testorderService.AddOrder(newOrder);
            testorderService.FindOrders(1);
            testorderService.FindOrders(2);
            testorderService.FindOrders("c");
            testorderService.FindOrders("e");
            testorderService.FindOrders(me);
            testorderService.FindOrders(new Customer(""));
            testorderService.FindOrdersLess(190);
            testorderService.FindOrdersAbove(190);
        }
        [TestMethod] //排序是否成功
        public void TestMethodSort()
        {
            OrderDetails newOrder1 = new OrderDetails();
            OrderDetails newOrder2 = new OrderDetails();
            Goods goods1 = new Goods("a", 10);
            newOrder1.Add(goods1, 3);
            newOrder2.Add(goods1, 5);
            Goods goods2 = new Goods("b", 9);
            newOrder1.Add(goods2, 5);
            newOrder2.Add(goods2, 1);
            Goods goods3 = new Goods("c", 8);
            newOrder1.Add(goods3, 13);
            newOrder2.Add(goods3, 100);
            OrderService testorderService1 = new OrderService();
            OrderService testorderService2 = new OrderService();
            OrderService testorderService3 = new OrderService();
            testorderService1.AddOrder(newOrder1);
            testorderService1.AddOrder(newOrder2);
            testorderService2.AddOrder(newOrder1);
            testorderService2.AddOrder(newOrder2);
            testorderService3.AddOrder(newOrder1);
            testorderService3.AddOrder(newOrder2);
            testorderService2.SortOrders(((a, b) => { if (a.Cost < b.Cost) a.Swap(b); }));
            testorderService3.SortOrders(((a, b) => { if (a.orderDetails.num[0] < b.orderDetails.num[0]) a.Swap( b); }));
            Console.WriteLine(testorderService1.orders[0].ToString());
            Console.WriteLine(testorderService2.orders[0].ToString());
            Console.WriteLine(testorderService3.orders[0].ToString());
            testorderService2.SortOrders();
            Console.WriteLine(testorderService2.orders[0].ToString());
        }
    }
}
